﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using ULog.Controllers;


using OF.Component.Model;
using OF.Utility;
using OF.Utility.Logging;
using System.Text;
using Swashbuckle.Swagger.Annotations;
using ULog.Common;
using ULog.Dto;


namespace ULog.Controllers
{
    /// <summary>
    /// 统一日志API
    /// </summary>
    public class LogController : BaseApiController
    {
        /// <summary>
        /// 
        /// </summary>
        [HttpGet]
        [AllowAnonymous]
    
        public void Test()
        {
            var errorLog = new ErrorLog()
            {
                CreatedDate = DateTime.Now,
                RequestMethod = "post",
                RequestUrl = "logtest"
            };
            ErrorLogHelper.Error(errorLog);

            var actionLog=new ActionLog()
            {
                CreatedDate = DateTime.Now,
                RequestMethod = "post",
                RequestUrl = "logtest"
            };
            ActionLogHelper.Info(actionLog);

            var optLog=new BusinessLog()
            {
                CreateDateTime = DateTime.Now,
                ModuleName = "logtestmodulename",
                MethodName = "logtestmethodName"
            };
            BizLogHelper.Operate(optLog);

        }

        /// <summary>
        /// 操作日志接口
        /// </summary> 
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public void Operate(BizLogRequest request)
        {            
            var oInfo=new BusinessLog();
            request.MergeTo(oInfo);
            BizLogHelper.Operate(oInfo);          
        }

        /// <summary>
        /// 错误日志接口
        /// </summary> 
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public void Error(ErrorLogRequest request)
        {           
            var oInfo=new ErrorLog();
            request.MergeTo(oInfo);
            ErrorLogHelper.Error(oInfo);          
        }

        /// <summary>
        /// 错误日志接口
        /// </summary> 
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public void Action(ActionLogRequest request)
        {
            var oInfo = new ActionLog();
            request.MergeTo(oInfo);
            ActionLogHelper.Info(oInfo);
        }
        
    }
}
